// pages/search/search.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    keyWord:'',
    searchRes:null,
    isNotRes:true
  },
  onChange(e) {
    this.setData({
      keyWord: e.detail,
    });
  },
  onClick(){
    if(this.data.keyWord.trim()){
      console.log(this.data.keyWord);
      const db = wx.cloud.database();
      db.collection('questions')
      .where({
        title:db.RegExp({
          regexp: this.data.keyWord,
          options:'i'
        })
      })
      .get()
      .then(res=>{
        console.log(res);
        if(res.data.length==0){
          this.setData({
            isNotRes:true
          })
        }else{
          this.setData({
            searchRes:res.data,
            isNotRes:false
          })
        }
      })
    }else{
      console.log(22);
      return
      
    }
    
  },
  goToDetail(e){
    // console.log(this.data.sort);
    wx.navigateTo({
      url: `/pages/question_detail/question_detail?kw=${this.data.keyWord}&index=${e.currentTarget.dataset.index}`,
    })
  }
})